/*
 *  Openmysee
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */
#ifndef __TRAYICONPOSITION_H_
#define __TRAYICONPOSITION_H_

#include <TIME.H>
#include <commctrl.h>
#include <shellapi.h>

class CTrayIconPosition  
{
public:
	typedef enum Precision { Default=0,Low,Medium,High };

	typedef enum TrackType { UseBothTechniquesDirectPrefered, 
							 UseBothTechniquesVisualScanPrefered,
							 UseDirectOnly,
							 UseVisualScanOnly};
	

	//Second tracking method: it detects a tray icon scaning tray area pixel by pixel
	void InitializePositionTracking(HWND a_hwndOfIconOwner, int a_iIconID);
	BOOL GetTrayIconPosition(POINT& a_ptPoint, TrackType a_eTrackType = UseBothTechniquesDirectPrefered, Precision a_ePrec = Default);
	void RestoreTrayIcon(HICON a_hIcon);

	//Those functions are for use with second tracking method - will cache tracking results
	void Invalidate();
	void SetPrecisionTimeOuts(int iLowSec, int iMedSec, int iHighSec);
	void SetDefaultPrecision(Precision newPrecision) { m_prDefaultPrecision = newPrecision; };
	Precision GetDefaultPrecision(void) { return m_prDefaultPrecision; };

	CTrayIconPosition();
	virtual ~CTrayIconPosition();

protected:
	HICON		m_hIconTemp;
	RECT		m_rtRectangleOfTheTray;
	Precision	m_prDefaultPrecision;
	time_t		m_tLastUpdate;
	POINT		m_ptPosition;
	int			m_iTrayIconID;
	HWND		m_hWndOfIconOwner;
	int			m_iPrecisions[3];  //This is table of time outs in seconds of low,med and high precision modes.
	OSVERSIONINFO m_osVer;

	//Tracking method: attaches to Tray process and reads data directly, is fast and reliable but will fail if user uses non standard tray software
	static BOOL FindOutPositionOfIconDirectly(const HWND a_hWndOwner, const int a_iButtonID, RECT& a_rcIcon);

	BOOL FindOutPositionOfIcon(HICON icon);
	inline BOOL CheckIfColorIsBlackOrNearBlack(COLORREF crColor);
	BOOL GetTrayIconPositionVisualScan(POINT& a_ptPoint, Precision a_ePrec);
	
	static RECT GetTrayWndRect();
	static HWND  GetTrayNotifyWnd(BOOL a_bSeekForEmbedToolbar);
	static BOOL CALLBACK FindTrayWnd(HWND hwnd, LPARAM lParam);
	static BOOL CALLBACK FindToolBarInTrayWnd(HWND hwnd, LPARAM lParam);
};

#endif
